package com.jsj.isdt.jdbc;

import com.jsj.isdt.entity.Goods;
import com.jsj.isdt.utils.DBUtils;

import java.sql.*;

public class dbDemo {
    public static void main(String[] args) throws ClassNotFoundException, SQLException {
//        //1.加载驱动
//        Class.forName("com.mysql.cj.jdbc.Driver");
//
//        //2.用户信息和URL
//        String url = "jdbc:mysql://localhost:3306/demo?useUnicode=true&characterEncoding=UTF8&useSSL=true&serverTimezone=UTC";
//        String username = "root";
//        String password = "123456";
//
//        //3.连接成功数据库对象 Connection代表数据库
//        Connection connection = DriverManager.getConnection(url, username, password);
//
//        //4.执行SQL的对象
//        Statement statement = connection.createStatement();
//
//        //5.执行SQL的对象去执行SQL，可能存在结果，查看返回结果
//        String sql = "SELECT * FROM user ";
//        ResultSet resultSet = statement.executeQuery(sql);//返回的结果集
//
//        while (resultSet.next()){
//
//            System.out.print(resultSet.getInt("id")+" ");
//            System.out.println(resultSet.getString("username")+" ");
//            System.out.println(resultSet.getString("password")+" ");
//        }
//
//        //6.释放连接
//        resultSet.close();
//        statement.close();
//
        try {
            String sql = "select * from goods limit 0,1";
        Goods g =    DBUtils.QueryBean(sql, Goods.class);
            System.out.println(g.toString());
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}